
package org.bridgen.lang.semantics.ast;
import java.util.*;
 


public class AltPattern extends MatchPattern implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public AltPattern clone() throws CloneNotSupportedException {
        AltPattern node = (AltPattern)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
     @SuppressWarnings({"unchecked", "cast"})  public AltPattern copy() {
      try {
          AltPattern node = (AltPattern)clone();
          if(children != null) node.children = (ASTNode[])children.clone();
          return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
    }
     @SuppressWarnings({"unchecked", "cast"})  public AltPattern fullCopy() {
        AltPattern res = (AltPattern)copy();
        for(int i = 0; i < getNumChildNoTransform(); i++) {
          ASTNode node = getChildNoTransform(i);
          if(node != null) node = node.fullCopy();
          res.setChild(node, i);
        }
        return res;
    }
    // Declared in PrettyPrint.jrag at line 334

    
    public void pp(StringBuffer buf) {
    	buf.append("(");
    	for (int i = 0; i < getNumValuePattern(); i++) {
    		getValuePattern(i).pp(buf);
    		if (i != getNumValuePattern()-1) {
    			buf.append(" | ");
    		}
    	}
    	buf.append(")");
    }

    // Declared in TypeCodeGen.jrag at line 239

	
	public void generateClassAttributes(String indent, StringBuffer buf) {
		for (int i = 0; i < getNumValuePattern(); i++) {
			ValuePattern pattern = getValuePattern(i);
			buf.append(indent + "\"" + pattern.value() + "\"");
			if (i != getNumValuePattern()-1) {
				buf.append(",\n");
			}
		}
		buf.append("\n");
	}

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 57

    public AltPattern() {
        super();

        setChild(new List(), 0);

    }

    // Declared in bridgit.ast at line 11


    // Declared in bridgit.ast line 57
    public AltPattern(List<ValuePattern> p0) {
        setChild(p0, 0);
    }

    // Declared in bridgit.ast at line 15


  protected int numChildren() {
    return 1;
  }

    // Declared in bridgit.ast at line 18

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 57
    public void setValuePatternList(List<ValuePattern> list) {
        setChild(list, 0);
    }

    // Declared in bridgit.ast at line 6


    private int getNumValuePattern = 0;

    // Declared in bridgit.ast at line 7

    public int getNumValuePattern() {
        return getValuePatternList().getNumChild();
    }

    // Declared in bridgit.ast at line 11


     @SuppressWarnings({"unchecked", "cast"})  public ValuePattern getValuePattern(int i) {
        return (ValuePattern)getValuePatternList().getChild(i);
    }

    // Declared in bridgit.ast at line 15


    public void addValuePattern(ValuePattern node) {
        List<ValuePattern> list = getValuePatternList();
        list.addChild(node);
    }

    // Declared in bridgit.ast at line 20


    public void setValuePattern(ValuePattern node, int i) {
        List<ValuePattern> list = getValuePatternList();
        list.setChild(node, i);
    }

    // Declared in bridgit.ast at line 24

    public List<ValuePattern> getValuePatterns() {
        return getValuePatternList();
    }

    // Declared in bridgit.ast at line 27

    public List<ValuePattern> getValuePatternsNoTransform() {
        return getValuePatternListNoTransform();
    }

    // Declared in bridgit.ast at line 31


     @SuppressWarnings({"unchecked", "cast"})  public List<ValuePattern> getValuePatternList() {
        return (List<ValuePattern>)getChild(0);
    }

    // Declared in bridgit.ast at line 35


     @SuppressWarnings({"unchecked", "cast"})  public List<ValuePattern> getValuePatternListNoTransform() {
        return (List<ValuePattern>)getChildNoTransform(0);
    }

    // Declared in PatternAnalysis.jrag at line 10
 @SuppressWarnings({"unchecked", "cast"})     public boolean startsWithValue() {
        boolean startsWithValue_value = startsWithValue_compute();
        return startsWithValue_value;
    }

    private boolean startsWithValue_compute() {  return true;  }

    // Declared in PatternAnalysis.jrag at line 39
 @SuppressWarnings({"unchecked", "cast"})     public boolean isAltPattern() {
        boolean isAltPattern_value = isAltPattern_compute();
        return isAltPattern_value;
    }

    private boolean isAltPattern_compute() {  return true;  }

    // Declared in TypeCodeGen.jrag at line 276
 @SuppressWarnings({"unchecked", "cast"})     public String value() {
        String value_value = value_compute();
        return value_value;
    }

    private String value_compute() {
		StringBuffer buf = new StringBuffer();
		if (getNumValuePattern() > 1) {
			buf.append("(");
		}
		for (int i = 0; i < getNumValuePattern(); i++) {
			ValuePattern pattern = getValuePattern(i);
			buf.append(pattern.value());
			if (i != getNumValuePattern()-1) {
				buf.append("|");
			}
		}
		if (getNumValuePattern() > 1) {
			buf.append(")");
		}
		return buf.toString();
	}

    // Declared in TypeCodeGen.jrag at line 339
 @SuppressWarnings({"unchecked", "cast"})     public String regExp() {
        String regExp_value = regExp_compute();
        return regExp_value;
    }

    private String regExp_compute() {
		StringBuffer buf = new StringBuffer();
		if (getNumValuePattern() > 1) {
			buf.append("(");
		}
		for (int i = 0; i < getNumValuePattern(); i++) {
			ValuePattern pattern = getValuePattern(i);
			buf.append(pattern.regExp());
			if (i != getNumValuePattern()-1) {
				buf.append("|");
			}
		}
		if (getNumValuePattern() > 1) {
			buf.append(")");
		}
		return buf.toString();
	}

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

}
